package com.fortune.service.impl;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.ListUtils;
import com.fortune.dal.dao.CustBankPointDAO;
import com.fortune.dal.model.CustBankPoint;
import com.fortune.service.CustBankPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustBankPointServiceImpl implements CustBankPointService {

    @Autowired
    private CustBankPointDAO custBankPointDAO ;

    @Override
    public void addCustBankPoint(CustBankPoint custBankPoint) throws BusinessException {
        try{
            custBankPointDAO.insert(custBankPoint);
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public void modifyCustBankPoint(CustBankPoint custBankPoint) throws BusinessException {
        try{
            custBankPointDAO.updateById(custBankPoint) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
    }

    @Override
    public CustBankPoint queryCustBankPoint(Integer custId, Integer bankId) throws BusinessException {
        CustBankPoint param = new CustBankPoint();
        param.setCustId(custId);
        param.setBankId(bankId);
        List<CustBankPoint> custBankPoints = queryCustBankPointList(param) ;
        if(ListUtils.isNotEmpty(custBankPoints)) {
            return custBankPoints.get(0) ;
        }
        return null;
    }

    @Override
    public CustBankPoint queryCustBankPoint(Integer custBankPointId) throws BusinessException {
        CustBankPoint c = null;
        try{
            c = custBankPointDAO.queryById(custBankPointId) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return c;
    }

    @Override
    public List<CustBankPoint> queryCustBankPointList(CustBankPoint custBankPoint) throws BusinessException {
        List<CustBankPoint> list = null;
        try{
            list = custBankPointDAO.queryByModel(custBankPoint) ;
        }catch (Exception ex) {
            BusinessException.throwBusinessException(ex);
        }
        return list;
    }
}
